<!DOCTYPE html>
<html>
<head>
	<title>react-form3</title>
    <meta charset="UTF-8" />
	<script src='../node_modules/react/umd/react.development.js'></script>
	<script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    
</head>
<body>
    <div id="my"></div>
    <script type="text/babel">
    class Hello extends React.Component{
        constructor(){
            super();
            this.state = {
                email:''
            };
        };
        handleEmail(e){
            var value = e.target.value;
            var filter=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            var error='';
            if(!filter.test(value)){
                error="请输入正确的Email"
            };
            this.setState({
                email:value,
                error:error
            })
        }
        submit() {
            alert(JSON.stringify(this.state))
        }
        
        render(){ 
            return (
                <div>
                    <p>
                        <label>email:</label>
                        <input type="text"
                          name='email'
                          value={this.state.email} 
                          onChange={(e)=>this.handleEmail(e)}/>
                          <span>{this.state.error}</span>
                    </p>
                    <p>
                        <button onClick={()=>this.submit()}>提交</button>
                    </p>
                </div>
                )
        }
    };
    
     ReactDOM.render(
          <Hello/>,
        document.getElementById('my')
    )
    </script>
</body>
</html>